$.ajax({
    type: "post",
    url: "/getJobArr",
    dataType: "json",
    success: function(res) {
        // console.log(res.data);
        let jobStr = ''
        res.data.forEach(item => {
            jobStr += `
            
            
          <li>
            <div class="find_up">
                <div class="find_info">
                    <h4>
                        <span>${item.job}</span>
                        <span>[${item.area}]</span>
                    </h4>
                    <p>
                        <span class="price">${item.price}</span>
                        <span>${item.workTime}</span>
                        <em class="vline"></em>
                        <span>${item.xueli}</span>
                        <span class="find_talk">
                            立即沟通
                        </span>
                    </p>

                </div>
                <div class="find_con">
                    <div class="con_info">
                        <h4>
                            ${item.name}
                        </h4>
                        <p>
                            <span>${item.hangye}</span>
                            <em class="vline"></em>
                            <span>${item.rongzi}</span>
                            <em class="vline"></em>
                            <span>${item.people}</span>
                        </p>
                    </div>
                    <div class="con_logo">
                        <img src="${item.imgUrl}">
                    </div>
                </div>
            </div>
            <div class="find_down">
                <div class="find_tec">
                    <span>${item.tec[0]}</span>
                    <span>${item.tec[1]}</span>
                     <span>${item.tec[2]}</span>
                    <span>${item.tec[3]}</span>
                     <span>${item.tec[4]}</span>
                   
                </div>
                <div class="find_fuli">
                   ${item.fuli}
                </div>
            </div>
        </li>
            
            
            
            `
        });


        $('.find_left ul').html(jobStr)
    }
});

let isTrue = false
$('.mphone>span').click(() => {
    if (isTrue == false) {
        $('.mp_hide').show()
        isTrue = true
    } else {
        $('.mp_hide').hide()
        isTrue = false
    }

    $.ajax({
        url: '/getPhone',
        type: 'post',
        dataType: 'json',
        success: res => {
            let phone_str = ''
            let phone_str1 = ''
            res.zpData.forEach(item => {
                item.array.forEach(it => {

                    phone_str1 += `<li>${it.country}
                    
                    <p>${it.code}</p>
                    
                    </li>`

                })

                phone_str += `<li class='disable'>${item.type}</li>${phone_str1}`
                phone_str1 = ''


            })
            $('.mp_hide ul').html(phone_str)
            $('.mp_hide li').click(function() {


                if ($(this).hasClass('disable')) {

                } else {
                    $('.mphone>span').text($(this).children('p').text())
                }

                if (isTrue == false) {
                    $('.mp_hide').show()
                    isTrue = true
                } else {
                    $('.mp_hide').hide()
                    isTrue = false
                }
            })


        }
    })
})



//搜索弹出框


$('.close').click(() => {
    $('.city_hide').hide()
})
$('.select').click(() => {
    $('.city_hide').show()
    $.ajax({
        url: '/getCity',
        type: 'post',
        dataType: 'json',
        success: res => {


            let hot_str = ''
            res.zpData.hotCityList.forEach(item => {
                hot_str += `<li class='hot_city'>

                <span>${item.name}</span>
                </li>`
            })

            $('.row_span').html(hot_str)
            $('.row_ul>li').click(function() {

                $(this).addClass('current').siblings().removeClass('current')


                let city_str = ''
                let city_str1 = ''

                let city_arr = []


                //将第一层和第二层的数组通过拓展符合并为一个数组
                city_arr.push(...res.zpData.cityList)
                res.zpData.cityList.forEach(item => {
                    city_arr.push(...item.subLevelModelList)

                })

                //使用reduce()设置数组对象去重
                let obj = {}
                let new_cityarr = city_arr.reduce((cur, next) => {
                        obj[next.name] ? '' : obj[next.name] = true && cur.push(next)
                        return cur

                    }, []) //设置cur初始值为空数组

                //筛选出不重复的数组

                //通过给定的字符,返回对应拼接的字符串
                function getFirstChar(str) {
                    let newArr = new_cityarr.filter(item => {
                        return item.firstChar == str
                    })
                    newArr.forEach(item => {
                        city_str1 += `<li>
                        <span class='city-cur'>${item.name}</span>
                        
                        </li>`
                    })

                    city_str = `<li class='normal_city'>
                        <div class='city_tit'>${str.toUpperCase()}</div>
                        <ul class='city-main'>${city_str1}</ul>
                        </li>`
                    city_str1 = ''
                    return city_str
                }
                switch ($(this).attr('data')) {
                    case '1':

                        $('.row_span').html(getFirstChar('a'))
                        $('.row_span').append(getFirstChar('b'))
                        $('.row_span').append(getFirstChar('c'))
                        $('.row_span').append(getFirstChar('d'))
                        $('.row_span').append(getFirstChar('e'))

                        break;
                    case '2':
                        $('.row_span').html(getFirstChar('f'))
                        $('.row_span').append(getFirstChar('g'))
                        $('.row_span').append(getFirstChar('h'))
                        $('.row_span').append(getFirstChar('j'))


                        break;
                    case '3':
                        $('.row_span').html(getFirstChar('k'))
                        $('.row_span').append(getFirstChar('l'))
                        $('.row_span').append(getFirstChar('m'))
                        $('.row_span').append(getFirstChar('n'))

                        break;
                    case '4':
                        $('.row_span').html(getFirstChar('p'))
                        $('.row_span').append(getFirstChar('q'))
                        $('.row_span').append(getFirstChar('r'))
                        $('.row_span').append(getFirstChar('s'))
                        $('.row_span').append(getFirstChar('t'))

                        break;
                    case '5':
                        $('.row_span').html(getFirstChar('w'))
                        $('.row_span').append(getFirstChar('x'))
                        $('.row_span').append(getFirstChar('y'))
                        $('.row_span').append(getFirstChar('z'))

                        break;

                    default:
                        $('.row_span').html(hot_str)
                        break;
                }

            })

        }

    })
})

$(document).scroll(() => {
    if ($(document).scrollTop() < $('body').height() - $('.city_hide').height()) {
        $('.city_hide').css('top', $(document).scrollTop())
    }
})

$.ajax({
    url: '/getCity',
    type: 'post',
    dataType: 'json',
    success: res => {


        let str_left = ''
        res.zpData.hotCityList.forEach(item => {
            str_left += `<li data='${item.code}'>${item.name}</li>`
        })

        $('.top>.str_left>ul').html(str_left)


        $('.top>.str_left>ul>li').click(function() {
            $(this).addClass('orange').siblings().removeClass('orange')
            if ($(this).text() == '全国') {
                $('.middle>ul').html('')
            } else {
                let old_liArr

                let new_liArr = res.zpData.cityList.map(item => {
                    if (item.subLevelModelList != null) {
                        old_liArr = item.subLevelModelList.filter(li => {
                            return li.name == $(this).text()

                        })
                        return old_liArr
                    }

                })

                let liArr_str = '<li>不限</li>'


                let New_Arr = new_liArr.filter(item => {
                    return item.length != 0
                })


                New_Arr[0][0].subLevelModelList.forEach(item => {
                    liArr_str += `<li>${item.name}</li>`
                })

                $('.middle>ul').html(liArr_str)

            }






        })

    }


})